﻿using SPW.GenericDesktop.Views;
using Prism.Ioc;
using Prism.Modularity;
using System.Windows;
using SPW.LogIn;
using SPW.Layout;
using SPW.SystemHeader;
using SPW.Aside;
using SPW.MainViewer;
using SPW.Infrastructure.Interfaces;
using CommonServiceLocator;
using SPW.Infrastructure.Utils;
using SPW.GenericDesktop.Codes;
using Prism.Events;

namespace SPW.GenericDesktop
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<IShell>() as Window;
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //初始化ServiceLocator
            ServiceLocator.SetLocatorProvider(() => Container.Resolve<IServiceLocator>());
            //获取唯一宿主窗口
            var owner = Container.Resolve<MainWindow>();
            //获取消息
            var eventAggregator = Container.Resolve<IEventAggregator>();
            //注册宿主窗口(IShell)
            containerRegistry.RegisterInstance(typeof(IShell), owner);
            //注册全局数据服务接口
            IDataServiceClient dataServiceClient = new SimpleRequestClient("http://localhost:8888");
            containerRegistry.RegisterInstance(typeof(IDataServiceClient), dataServiceClient);
            //注册APP配置
            containerRegistry.RegisterInstance(typeof(IRunSettings), new RunSettings());
            //注册 ISGWorld
            containerRegistry.RegisterInstance(typeof(ISGWorld), new SGWorldManager(eventAggregator));
        }

        protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
        {
            //基础模块
            moduleCatalog.AddModule<LogInModule>();
            moduleCatalog.AddModule<LayoutModule>();
            moduleCatalog.AddModule<SystemHeaderModule>();
            moduleCatalog.AddModule<MainViewerModule>();
            moduleCatalog.AddModule<AsideModule>();
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new DirectoryModuleCatalog() { ModulePath = @".\Modules" };
        }
    }
}
